import { ecs } from 'db://app-game/libs/ecs/ECS';
import { app } from 'db://app-game/core/app';
import { Node, UITransform } from 'cc';
import { CameraModelComp } from './model/CameraModelComp';

/** 游戏摄像机实例 */
@ecs.register('GameCamera')
export class GameCamera extends ecs.Entity {
  // 数据层
  CameraModel: CameraModelComp;

  // 视图层
  init() {
    this.add(CameraModelComp);
    this.CameraModel.cameraNode = app.gui.camera.node;
    const canvasUI = app.gui.root.getComponent(UITransform);
    this.CameraModel.renderWidth = canvasUI.width;
    this.CameraModel.renderHeight = canvasUI.height;
  }

  setfollowTarget(target: Node) {
    this.CameraModel.target = target;
  }
}
